package perform.database;

import java.lang.reflect.Field;

import perform.annotations.ManyToOne;
import perform.constants.Index;
import perform.mappings.ClassMappings;

public class ManyToOneProcessor extends ForeignKeyProcessor {
	
	private ManyToOne manyToOne;

	public ManyToOneProcessor(Field field, String name) {
		super(field, name);
		manyToOne = field.getAnnotation(ManyToOne.class);
		target = manyToOne.target();
		idColumn = ClassMappings.getIDColumnProcessor(target);
		name = manyToOne.name();
		if(name.equals("")){
			name = field.getName();
		}
		cascade = manyToOne.cascade();
		if(name.equals("")){
			name = field.getName();
		}
		buildColumnDefinition();
		buildForeignDefinition();
	}
	
	@Override
	public boolean isNullable() {
		return manyToOne.nullable();
	}
	@Override
	public boolean isIndex() {
		return false;
	}
	@Override
	public Index getIndex() {
		return null;
	}

}
